package com.test.library;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.util.Log;

import java.io.InputStream;


public class Util {
    public static void test() {
        Log.e("test", "test");
    }

    public static Bitmap getBitmapFromResource(Context context, String resName) {
        InputStream inputStream = context.getClass().getResourceAsStream(resName);
        return BitmapFactory.decodeStream(inputStream);
    }

    public static Drawable getDrawableFromResource(Context context, String resName) {
        return new BitmapDrawable(getBitmapFromResource(context, resName));
    }

    public static StateListDrawable getStateListDrawable(Context context, String normalRes, String selectRes) {
        StateListDrawable stateListDrawable = new StateListDrawable();
        Drawable normalDrawable = getDrawableFromResource(context, normalRes);
        Drawable selectDrawable = getDrawableFromResource(context, selectRes);
        stateListDrawable.addState(new int[]{-android.R.attr.state_focused, -android.R.attr.state_selected, -android.R.attr.state_pressed}, normalDrawable);
        stateListDrawable.addState(new int[]{-android.R.attr.state_focused, -android.R.attr.state_selected, android.R.attr.state_pressed}, selectDrawable);
        stateListDrawable.addState(new int[]{-android.R.attr.state_focused, android.R.attr.state_selected, -android.R.attr.state_pressed}, selectDrawable);
        stateListDrawable.addState(new int[]{android.R.attr.state_focused, -android.R.attr.state_selected, -android.R.attr.state_pressed}, selectDrawable);
        return stateListDrawable;
    }
}
